home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / AppleScanGS / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-03  |  6.6 KB  |  230 lines  |  [TEXT/MPS ]

  1. /***********************************************************************
  2. *
  3. * Menu.c
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1989
  7. * All Rights Reserved.
  8. *
  9. * This file contains the code which implements 
  10. * menus in the scanner program.
  11. *
  12. ***********************************************************************/
  13.  
  14. #include <control.h>
  15. #include <types.h>
  16. #include <quickdraw.h>
  17. #include <qdaux.h>
  18. #include <window.h>
  19. #include <event.h>
  20. #include <menu.h>
  21. #include <desk.h>
  22. #include <intmath.h>
  23. #include <stdfile.h>
  24. #include <gsos.h>
  25. #include <memory.h>
  26. #include <malloc.h>
  27.  
  28. #include "Scan.h"
  29.  
  30. extern WmTaskRec        event;
  31. extern unsigned int     quitFlag;
  32. extern GrafPortPtr        previewWindow;
  33. extern GrafPortPtr        settingsWindowPtr;
  34. extern GrafPortPtr        openThisWindow();
  35.  
  36. SFReplyRec2        MyReply;
  37.  
  38. extern void doCloseTop();
  39.  
  40. void    doQuitItem();
  41. void    doAboutBox();
  42. void    doOpenItem();
  43. void    doSaveItem();
  44. void    doSaveAsItem();
  45. void    doPrefItem();
  46. void    doSettingsItem();
  47. void    doPreviewItem();
  48.  
  49. /* array of procedure address to handle menu selections */
  50. void (*menuProc[])() = {
  51.         doAboutBox,            /* for Undo */
  52.         doAboutBox,            /* for Cut */
  53.         doAboutBox,            /* for Copy */
  54.         doAboutBox,            /* for Paste */
  55.         doAboutBox,            /* for Clear */
  56.         doCloseTop,            /* for Close */
  57.         doAboutBox,            /* for About (really!) */
  58.         doOpenItem,            /* for Open */
  59.         doSaveItem,            /* for Save */
  60.         doSaveAsItem,        /* for Save As */
  61.         doPrefItem,            /* for Preferences */
  62.         doAboutBox,            /* for Print */
  63.         doQuitItem,            /* for Quit */
  64.         doSettingsItem,        /* for Settings (in Scan menu) */
  65.         doPreviewItem        /* for Preview (in Scan Menu) */
  66. };
  67.  
  68. /**********************************************************************/
  69.  
  70. void    doQuitItem()
  71. {
  72.     quitFlag++;
  73. }
  74.  
  75. /**********************************************************************/
  76.  
  77. void    doAboutBox()
  78. {
  79.     AlertWindow(4, NULL, (long) AboutBox);
  80. }
  81.  
  82. /**********************************************************************/
  83.  
  84. void    doOpenItem()
  85. {
  86.     AlertWindow(4, NULL, (long) AboutBox);
  87. }
  88.  
  89. /**********************************************************************/
  90. /**********************************************************************/
  91.  
  92. void    doSaveItem()
  93. {
  94.     AlertWindow(4, NULL, (long) AboutBox);
  95. }
  96.  
  97. /**********************************************************************/
  98. /**********************************************************************/
  99.  
  100. void doSaveAsItem()
  101. {
  102.     extern int        SavePic();
  103.     LocInfoHndl        AuxHandle;
  104.     LocInfoPtr        RefPtr;
  105.     ResultBuf255Ptr    filename;
  106.     GrafPortPtr        WhichWindow;
  107.     GSString255Ptr    oldfilename;
  108.     char            *windowName, **nameHndl;
  109.     int                i, error;
  110.  
  111.     RefPtr = (LocInfoPtr) GetWRefCon((WhichWindow = FrontWindow()));
  112.     
  113.     nameHndl = (char **) GetWTitle(WhichWindow);    /* get the current window title */
  114.     if((unsigned long) nameHndl & 0x80000000) {    /* returned as a handle? */
  115.         windowName = *nameHndl;        /* yes, dereference it */
  116.         nameHndl = NULL;            /* then clear it so we don't dispose of it later */
  117.     } else
  118.         windowName = (char *) nameHndl;    /* else must be a real pointer */
  119.  
  120.     oldfilename = (GSString255Ptr) malloc(*windowName+2);    /* convert to GSOS string */
  121.     memcpy(oldfilename->text, windowName+2, (oldfilename->length = *windowName-2));
  122.     
  123.     MyReply.nameDesc = MyReply.nameDesc = 3;        /* let StdFile allocate the memory for the names */
  124.  
  125.     SFPutFile2 (25,30,
  126.         0,"\pSave picture as:",
  127.         0, oldfilename,
  128.         &MyReply);
  129.  
  130.     if (MyReply.good) {                                    /* <> 0 --> OK to save it */
  131.         filename = (ResultBuf255Ptr) *((ResultBuf255Ptr *) MyReply.pathRef);
  132.         if(error = /* assignment */ SavePic(&(filename->bufString), RefPtr))    /* save the picture */
  133.             ErrorWindow(0,NULL,error);
  134.         else {
  135.             filename =  * ((ResultBuf255Ptr *) MyReply.nameRef);    /* get pointer to filename result */
  136.             windowName = malloc((i = filename->bufString.length)+3);    /* get the buffer */
  137.             windowName[0] = i + 2;        /* set the new length (pascal string) */
  138.             memcpy(windowName+2,filename->bufString.text,i);    /* copy the new name in */
  139.             windowName[1] = windowName[i+2] = ' ';
  140.             
  141.             SetWTitle(windowName,WhichWindow);    /* change the window name */
  142.             if(nameHndl)    /* if name was returned as a pointer... */
  143.                 free(nameHndl);    /* then dispose of the old name */
  144.         }
  145.     }
  146.     DisposeHandle(MyReply.nameRef);
  147.     DisposeHandle(MyReply.pathRef);
  148.     free(oldfilename);
  149. }
  150.  
  151. /**********************************************************************/
  152.  
  153. void    doPrefItem()
  154. {
  155.     AlertWindow(4, NULL, (long) AboutBox);
  156. }
  157.  
  158. /**********************************************************************/
  159.  
  160. void    doSettingsItem()
  161. {
  162.     Pointer        theArrayList[1];
  163.     static char    subString[] = {"0000"};
  164.     CtlRecHndl    ctlHandle;
  165.     extern void    scrollAction();
  166.     extern int    scanDevnum;
  167.  
  168.     if(settingsWindowPtr == NULL) {
  169.         settingsWindowPtr = openThisWindow(SettingsWindow);
  170.         if(!scanDevnum) {    /* if a scanner wasn't found during initialization */
  171.             HiliteControl(inactiveHilite, GetCtlHandleFromID(settingsWindowPtr,ScanButton));    /* disable the buttons */
  172.             HiliteControl(inactiveHilite, GetCtlHandleFromID(settingsWindowPtr,PreviewButton));
  173.         }
  174.         EnableMItem(CloseID);
  175.         SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,BrightnessScroll));
  176.         SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,ContrastScroll));
  177.         SetCtlAction(scrollAction,GetCtlHandleFromID(NULL,ThresholdScroll));
  178.  
  179.     } else
  180.         SelectWindow(settingsWindowPtr);
  181.  
  182. }
  183.  
  184. /**********************************************************************/
  185.  
  186. void    doPreviewItem()
  187. {
  188.     openPreview();
  189. }
  190.  
  191. /**********************************************************************/
  192.  
  193. void    doMenu()
  194. {
  195.     unsigned int    menuNum, itemNum;
  196.     unsigned int    *intPtr;
  197.  
  198.     /* Procedure to handle all menu selections.  Examines the event.TaskData
  199.     ** menu item ID word from TaskMaster (from Event Manager) and calls the
  200.     ** appropriate routine.  While the routine is running the menu title is
  201.     ** still highlighted.  After the routine returns, we unhilight the
  202.     ** menu title.
  203.     */
  204.  
  205.     intPtr = (unsigned *) &(event.wmTaskData);
  206.     menuNum = intPtr[1];        /* get high word of TaskData */
  207.     
  208. /*  menuNum = HiWord(event.wmTaskData);
  209.     itemNum = LoWord(event.wmTaskData);*/
  210.  
  211.     (*menuProc[*intPtr-250])();    /* call the menu handler */
  212.     
  213.     HiliteMenu(0, menuNum);     /* Unhighlight the menu title. */
  214. }
  215.  
  216. /**********************************************************************/
  217.  
  218. void    setupMenus()
  219. {
  220.     /* Procedure to install our menu titles and their items in the system menu
  221.     ** bar and to redraw it so we can see them.
  222.     */
  223.  
  224.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  225.     SetMenuBar(NULL);
  226.     
  227.     FixAppleMenu(AppleMenuID);              /* Add DAs to apple menu     */
  228.     FixMenuBar();                           /* Set sizes of menus        */
  229.     DrawMenuBar();                          /* ...and draw the menu bar! */
  230. }